#-------------------------------------------------------------------------------
# Name:        模块1
# Purpose:
#
# Author:      sy
#
# Created:
# Copyright:   (c) sy
# Licence:     <your licence>
#-------------------------------------------------------------------------------
#  这是 mtk 项目的camera
import uiautomator2 as u2
import time
##import sys
import os

with open("and_sn.txt", "r") as f:
    and_sn = f.readline()
    print(and_sn)

d = u2.connect("{}".format(and_sn))
if __name__ == '__main__':
    d = u2.connect()


f.close()
class power_1():
##    def devices_connect(*args):
##        d = u2.connect("{}".format(args))
    def connect_int():
        with open("and_sn.txt", "r") as f:
            and_sn = f.readline()
            print(and_sn)

        d = u2.connect("{}".format(and_sn))
    def stop_int():
        d.shell('pkill  atx-agent')
        d.app_stop_all()
        d.service("uiautomator").stop()
    def power_button():
        d.shell("input keyevent --longpress 26")
    def wait_device():
        os.system("adb -s {} wait-for-device".format(and_sn))
    def reboot_1():
        d.shell("input keyevent --longpress 26")
        d(resourceId="android:id/message", text="Restart").click()
        d(resourceId="android:id/button1").click()
        os.system("adb -s {} wait-for-device".format(and_sn))
    def reboot_9():
        #这是9的菜单
        d.shell("input keyevent --longpress 26")
        d(resourceId="android:id/message", text="Reboot").click()
        d(resourceId="android:id/button1").click()
        os.system("adb -s {} wait-for-device".format(and_sn))






'''
获取开关按钮的 开关属性值，进行判断
dd = d(resourceId="com.android.settings:id/switch_widget").get_text()
#print(dd)
if dd == "OFF":
    print("1")
elif dd == "ON":
    print("2")

灭屏亮屏
d.screen_on()
d.screen_off()

弹出关机菜单，并关机
d.shell("input keyevent --longpress 26")
d(resourceId="android:id/message", text="Restart").click()
d(resourceId="android:id/button1").click()


向上滑动
d(scrollable=True).scroll.vert.backward()

竖直滑动到结尾
d(scrollable=True).scroll.toEnd(60)

向下滑动
d(scrollable=True).scroll(steps=30)

竖直滑动到开头
d(scrollable=True).scroll.toBeginning(steps=60)

水平向右滑动
d(scrollable=True).scroll.horiz.forward(steps=60)

水平向右滑动，直到最右边
d(scrollable=True).scroll.horiz.toEnd(steps=50, max_swipes=500)

水平向左滑动
d(scrollable=True).scroll.horiz.backward(steps=50)

水平向左滑动，直到最左边
d(scrollable=True).scroll.horiz.toBeginning(steps=100, max_swipes=1000)

拖动
d(text="Settings").drag_to(x, y, duration=0.5)


'''



#camera_1.swipe_home_camera()

#xml = d.dump_hierarchy()

##d(description="应用").click()
##d(description="Apps").click()
##d(description="Apps").click()
##d(resourceId="com.android.systemui:id/recent_apps").click()
def main():
    pass


